package com.seari.main;

import java.util.Properties;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.seari.Utils.MiscTools;
import com.seari.Utils.SpringContainer;
import com.seari.commonutils.redis.JedisUtilProxy;
import com.seari.kafka.KafkaSender;
import com.seari.web.controller.EmpController;
import com.seari.web.controller.PostIdController;

@Component
@Order(value = 1)
public class StartUpClass implements ApplicationRunner
{

	@Autowired
	EmpController emp;
	
	@Autowired
	PostIdController post;
	
	protected static Logger logger = LoggerFactory.getLogger(StartUpClass.class);
	public static Properties config;
	static String configFilePath = "config.cfg";

	@Override
	public void run(ApplicationArguments args) throws Exception
	{
		System.out.println("start up class loading...");
		JedisUtilProxy.initJedisPoolUtil("127.0.0.1", 6379);
		emp.initDataBase();
		post.initPostDataBase();
//		KafkaSender sender = SpringContainer.getBean(KafkaSender.class);
//		for (int i = 0; i < 100; i++)
//		{
//			sender.send();
//		}
		init();
	}

	public void init()
	{
		try
		{
			config = MiscTools.loadConfig(configFilePath);
		} catch (Exception e)
		{
			// TODO: handle exception
			logger.warn(e.getMessage());
		}
		logger.info("read config file complete");
	}
}
